library(dplyr)
library(magrittr)


setClass('ampseq', slots = c(
  gt = "ANY",
  metadata = "ANY",
  markers = "ANY",
  loci_performance = "ANY",
  pop_summary = "ANY",
  controls = "ANY",
  discarded_loci = "ANY",
  discarded_samples = "ANY",
  plots = "ANY"
))

load(params$RData_image)

The haplotype of each sample is stored in the table aacigar_table within the object drug_resistant_haplotypes_plot.

plot_relatedness_distribution_between$plot
**Figure 1:** IBD distribution between sites

Figure 1: IBD distribution between sites

plot_frac_highly_related_between$plot
**Figure 2:** Frequency of highly related among sites

Figure 2: Frequency of highly related among sites

if(!is.na(Variable2)){plot_frac_highly_related_overtime_between$plot_IBD_correlation_matrix}
**Figure 2:** Frequency of highly related between sites over time

Figure 2: Frequency of highly related between sites over time

if(!is.na(Variable2)){plot_frac_highly_related_overtime_between$plot_frac_highly_related}
**Figure 2:** Frequency of highly related between sites over time

Figure 2: Frequency of highly related between sites over time

IBD_PCA
**Figure 3:** IBD PCA

Figure 3: IBD PCA

qual_col_pals = brewer.pal.info[brewer.pal.info$category == 'qual',]
col_vector = unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals)))

set.seed(1)

plot_network(pairwise_relatedness,
                               threshold = ibd_thres,
                               metadata = ampseq_object@metadata, 
                               sample_id = 'Sample_id', 
                               group_by = Variable1, 
                               levels = levels(as.factor(ampseq_object@metadata[[Variable1]])),
                               colors = sample(col_vector, nlevels(as.factor(ampseq_object@metadata[[Variable1]])))
                              )
**Figure 4:** IBD network

Figure 4: IBD network

## $network_object
## IGRAPH 6155350 UN-- 670 8289 -- 
## + attr: name (v/c)
## + edges from 6155350 (vertex names):
##  [1] G4G1103--G4G1050 G4G1103--G4G1153 G4G1103--G4G1649 G4G1103--G4G2071 G4G1103--G4G2268 G4G1103--G4G2471 G4G1103--G4G2567 G4G1103--G4G2938 G4G1103--G4G2999 G4G1103--G4G2872
## [11] G4G1103--G4G3267 G4G1103--MH-212  G4G1106--G4G1458 G4G1106--G4G1193 G4G1106--G4G1342 G4G1106--G4G2583 G4G1106--G4G2612 G4G1106--G4G2487 G4G1106--G4G3159 G4G1106--G4G2786
## [21] G4G1106--MH-273  G4G1106--MP0172  G4G1106--MP0136  G4G1106--MP0031  G4G1106--MP0034  G4G1106--MP0041  G4G1106--MP0093  G4G1106--MP0023  G4G1107--G4G1415 G4G1107--G4G1031
## [31] G4G1050--G4G1107 G4G1153--G4G1107 G4G1107--G4G1198 G4G1342--G4G1107 G4G1107--G4G1607 G4G2268--G4G1107 G4G1107--G4G2396 G4G2471--G4G1107 G4G2567--G4G1107 G4G1107--G4G3143
## [41] G4G1107--G4G2817 G4G2872--G4G1107 G4G3267--G4G1107 G4G1107--G4G3299 G4G1107--G4G3384 G4G1107--MP0016  MP0136 --G4G1107 G4G1107--MP0051  MP0041 --G4G1107 G4G1107--MP0109 
## [51] G4G1415--G4G1124 G4G1124--G4G1425 G4G1124--G4G1100 G4G1124--G4G1109 G4G1124--G4G1150 G4G1124--G4G1481 G4G1124--G4G1544 G4G1124--G4G1736 G4G1124--G4G1794 G4G1124--G4G1847
## [61] G4G1124--G4G2143 G4G1124--G4G2145 G4G1124--G4G2459 G4G1124--G4G2306 G4G1124--G4G2652 G4G1124--G4G2688 G4G1124--G4G2728 G4G1124--G4G2976 G4G1124--G4G3126 G4G1124--G4G3402
## [71] G4G1124--G4G3062 G4G1124--G4G3293 G4G1124--G4G3408 G4G1124--MP0144  G4G1124--MP0062  G4G1124--MP0065  G4G1125--G4G1286 G4G1125--G4G1041 G4G1153--G4G1125 G4G1342--G4G1125
## + ... omitted several edges
## 
## $plot_network
## NULL

Pairwise relatedness comparisons between categories of Variable1

plot_relatedness_distribution_between$relatedness %>%
  DT::datatable(extensions = 'Buttons',
                options = list(dom = 'Blfrtip',
                  buttons = c('csv', 'excel')))